//
//  HMTextAttachment.swift
//  Weibo
//
//  Created by ZhuDong on 16/6/2.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HMTextAttachment: NSTextAttachment {
    var chs:String?
    class func getImageTextWithEmotion(emotion:HMEmotion,font: UIFont)->NSAttributedString{
        let attach = HMTextAttachment()
        attach.chs = emotion.chs
        let image = UIImage(named: emotion.imagePath ?? "")
        attach.image = image
        let lineH = font.lineHeight ?? 0
        attach.bounds = CGRect(x: 0, y: -4, width: lineH, height: lineH)
        let imageText = NSAttributedString(attachment: attach)
        let imageTextM = NSMutableAttributedString(attributedString: imageText)
        imageTextM.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0,length: 1))
        return imageTextM
    }
}
